package edu.govschool2010.shared;

import java.io.*;
import java.util.ArrayList;
import android.app.Activity;
import android.location.Location;



public class ReadFromFile extends Activity{
	
	private static ReadFromFile instance = null;
	
	private ReadFromFile(){
		
	}

	public static ReadFromFile getInstanceR(){

		if (instance == null){
			instance = new ReadFromFile();
		}
		return instance;
	}
	

	public boolean Read(ArrayList<Situation> list){	//need to call getInstanceR() first
		//returns whether the document was successfully read or not
		boolean docRead = true;
		ArrayList <String> order = new ArrayList <String>();


		try{
			FileInputStream fis = openFileInput("Priority.txt");
			BufferedReader br = new BufferedReader (new InputStreamReader(fis));
			
			while (br.readLine() != null) {
				order.add(br.readLine());
			}
			
			for (int x =0; x<= order.size()-1; x++){
				
				String FILE_NAME = order.get(x) + ".txt";
				BufferedReader br2 = new BufferedReader (new InputStreamReader(openFileInput(FILE_NAME)));
				list.get(x).situationName = br2.readLine();
				list.get(x).awayMessageText = br2.readLine();		
				list.get(x).startTime =new Long(br2.readLine()).longValue();//right? ...new Long(..);
				list.get(x).endTime =new Long(br2.readLine()).longValue(); //is this right?
				list.get(x).wifi = new Boolean(br2.readLine()).booleanValue();
				list.get(x).bluetooth = new Boolean(br2.readLine()).booleanValue();
				list.get(x).gps = new Boolean(br2.readLine()).booleanValue();
				list.get(x).airplaneMode = new Boolean(br2.readLine()).booleanValue();
				list.get(x).awayMessage = new Boolean(br2.readLine()).booleanValue();
				list.get(x).volume = new Integer(br2.readLine()).intValue();
				list.get(x).ringerMode= new Integer(br2.readLine()).intValue();
				list.get(x).brightness = br2.readLine();
				for (int y = 0; y<=6; y++){
					list.get(x).daysOfWeek[y] = new Boolean(br2.readLine()).booleanValue();
				}
				list.get(x).loc = new Location(br2.readLine());
				list.get(x).contact = br2.readLine();

			}


		}
		catch (FileNotFoundException e1) {
			docRead = false;
		}
		catch (IOException e2){
			docRead = false;
		}
		catch (Exception e){
			docRead = false;
		}
		finally {
			
			}
		return docRead;
	}
	
}
